<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="app">
    <home></home>
  </div>

  <script src="./vue.js"></script>
  <script>
    const Child = {
      template:`
        <h5>我是子组件</h5>
      `,
      data(){
        return {
          msg:'我是子组件'
        }
      },
      methods:{
        fn(){
          alert(1)
        }
      }
    }
    const Home = {
      template:`
        <div>
          <h3 ref="title">home组件</h3>
          <button ref="btn">按钮</button>
          <child ref="child"></child>
        </div>
      `,
      mounted() {
        // 在这个组件的 dom 编译完成后 自动触发 
        // console.log(document.querySelector('button'))
        console.log(this.$refs);
        this.$refs.title.style.background="blue"
        console.log(this.$refs.child.msg)
        this.$refs.child.fn()
      },
      components:{
        Child
      }
    }
    Vue.component('Home', Home)
    
    const vm = new Vue({
      el:'#app'
    })
  </script>
</body>
</html>